package com.example.educms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.educms.entity.CrmBanner;
import com.example.educms.service.CrmBannerService;
import com.example.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author xiuxian
 * @since 2022-06-30
 */
///后台系统的接口            后面在实现
//@CrossOrigin  //跨域
@RestController
@RequestMapping("/educms/bannerAdmin")
public class CrmBannerAdminController {

    @Autowired
    private CrmBannerService bannerService;

    //分页查询banner

    @GetMapping("/pageBanner/{page}/{limit}")
    public R pageBanner(@PathVariable long page, @PathVariable long limit){
        Page<CrmBanner> bannerPage=new Page<>(page,limit);
        bannerService.page(bannerPage,null);
        return  R.ok().data("rows",bannerPage.getRecords()).data("total",bannerPage.getTotal());

    }
    //添加
    @PostMapping("/addBanner")
    public   R  addBanner(@RequestBody CrmBanner crmBanner){
        bannerService.save(crmBanner);
        return  R.ok();
    }

    //修改
    @PostMapping("/updateBanner")
    public   R  updateBanner(@RequestBody CrmBanner crmBanner){
        bannerService.updateById(crmBanner);
        return  R.ok();
    }

    //get
    @GetMapping("/get/{id}")
    public  R getBanner(@PathVariable String id){
        bannerService.getById(id);
        return  R.ok();
    }

    //删除
    @DeleteMapping("/{id}")
    public  R  deleteBanner(@PathVariable String id){
        bannerService.removeById(id);
        return  R.ok();

    }

}

